package com.yaoyao.ex;

public class Method_demo {
    public static void main(String[] args) {
        System.out.println(add(10));
        parity(7);
        int[] arr1 = null;
        print_arr(arr1);
    }

    public static int add(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += i;
        }
        return sum;
    }

    public static void parity(int n) {
        if (n % 2 == 0) {
            System.out.println(n + "是一个偶数");
        } else {
            System.out.println(n + "是一个奇数");
        }
    }

    public static void print_arr(int[] arr) {
        if(arr == null){
            System.out.println(arr);
            return;
        }
        System.out.print("[");
//        for (int i = 0; i < arr.length-1; i++) {
//            System.out.print(arr[i]+",");
//        }
//        System.out.print(arr[arr.length-1]);
//        更简洁的方法
        for (int i = 0; i < arr.length; i++) {
            System.out.print(i == arr.length - 1 ? arr[i] : arr[i] + ",");
        }
        System.out.print("]");
    }

}
